var merchantServiceNative = require('../services/MerchantService');
var storeServiceNative = require('../services/storeService');
var errorHandler = require('../common/errorHandler');
var async = require("async");

var MerchantController = {
	getMerchantOne: function (req, res, next) {
	    var storeService = errorHandler.errorToResponse(req, res, storeServiceNative);
        var merchantService = errorHandler.errorToResponse(req, res, merchantServiceNative);

		var merchantId = "";
		var sendData = '';
		async.series(
			[
				function (cb) {
					storeService.getStoreById(req.params.id, '', function (err, store) {
						if (err) {
							return res.status(500).send(err);
						}
						merchantId = store.merchant_id;
						cb(err, store);
					})
				},
				function (cb) {
					merchantService.getMerchantById(merchantId, function (err, data) {
						if (err) return res.send("");
						sendData = data;
						cb(err, data);
					})
				}
			],
			function (err, result) {
				res.send(sendData);
			}
		);

	}
}


module.exports = MerchantController;